/** @jsxImportSource @emotion/react */
import * as React from "react";
import {  OriginalViewProps,  } from "../../common/base";
import {
  ResultDiagram, EvaluationForm, config测量仪, EntranceSetup
} from "./orcBase";
import {createItem, EditorAreaConfig, } from "../../common/eHelper";
import {useRecordListSub, useRecordListSubX} from "../../hook/useRecordListSub";
import {Instrument} from "./editor";
import {EditStorageContext} from "../../StorageContext";

/**给config测量仪的编辑字段提供默认赋值；   原本默认=undefined;
 * 【注意】只有打开编辑器确认才有生效的；还有问题，这么处理后，若需要真正的改成为空的，必须录入空格' '字符串才能成事，否则还是默认值。适配字符型的存储字段。
 * */
const defvcbFunc = (par: any) => {
  if(!par.表面)  par.表面='经表面处理后';
  if(!par.检测面)  par.检测面='外表面';
  return  par;
};


const recordPrintList = [
  createItem('Instrument', <Instrument config={config测量仪} label={'超声波检测-概况'} defValCb={defvcbFunc}>
      </Instrument>),
  createItem('EvaluationForm', <EvaluationForm/>),
  createItem('ResultDiagram', <ResultDiagram/>),
] as EditorAreaConfig[];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('Entrance', <EntranceSetup/>));

export const OriginalView=
    React.forwardRef((
        { action: modAction,  verId, repId='', rep}
            :OriginalViewProps, ref
    ) => {
      const {storage, } =React.useContext(EditStorageContext) as any;
      const { _SONIC_TS: SubRepIds }=storage;
      //为了避免hook报错的！
      // if(undefined===SubRepIds)
      //   return  <div>还没数据</div>;
      return <OriginalViewInner ref={ref} action={modAction} verId={verId} repId={repId} rep={rep}/>
} );

/**为了解决useProjectListAs({count: refCount } )因为变动{前面storage数据{有SONIC_TS没有THICK_MS}和后面storage{有THICK_MS}数据不一样的}，导致hook报错！
 * 只好拆分成2层次嵌套拼装的俩组件了。父组件可以逻辑return子组件可用hook，不违反hook规则不报错。
 * */
const OriginalViewInner=
    React.forwardRef((
        { action: modAction,  verId, repId='', rep}
            :OriginalViewProps, ref
    ) => {
      const titleRender = (store: any) => {
        const firstTag=store?.评定表?.[0]?.n;
        return <> { `[${firstTag}] `}
        </>;
      }
      const {list}=useRecordListSubX(ref,rep,repId,recordPrintList,modAction,verId,'SONIC_TS',titleRender);
      return <React.Fragment>
        {list}
      </React.Fragment>;
} );

//可嵌入式的公共分项报告:还不能做简易版原始记录的打印。点跳转hook报错；直接输上originalView URL有时没效编辑区内容。LoadableComponent useProjectListAs(会从3个跳成6个)报错SubRepIds为空跳变storage={}需要屏蔽？
